package cn.sintang.core.list.bean;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * User 用户信息
 * @author tangxy
 * @since 1.0.0
 * @date 2017-11-21
 */
public class User implements Serializable {

    private static final long serialVersionUID = 6629808364140643364L;
    /**
     * 主见编码
     */
    private String id;
    /**
     * 姓名
     */
    private String userName;
    /**
     * 年龄
     */
    private int age;
    /**
     * 身份证号码
     */
    private String idCard;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public User(String id, String userName, int age, String idCard) {
        this.id = id;
        this.userName = userName;
        this.age = age;
        this.idCard = idCard;
    }

    @Override
    public String toString() {
        return id+","+userName+","+age+","+idCard;
    }



    /**
     * 使用Set过滤重复数据
     * hashCode一样就会比较equals
     */

    @Override
    public boolean equals(Object obj) {
        if(obj == null || getClass() != obj.getClass()){
            return false;
        }
        if(obj == this){
            return true;
        }
        User user = (User) obj;
        boolean isSampleName = false;
        if(StringUtils.isNotBlank(userName) && userName.equals(user.getUserName())){
            isSampleName = true;
        }
        if(isSampleName && StringUtils.isNotBlank(idCard) && idCard.equals(user.getIdCard())){
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return 1;
    }
}
